package server.simon;

import java.io.IOException;
import java.util.concurrent.BlockingQueue;

import org.apache.log4j.Logger;

import server.container.EinsatzAlarm;
import de.root1.simon.Registry;
import de.root1.simon.Simon;
import de.root1.simon.exceptions.NameBindingException;

public class SimonServer {

	/**
	 * 
	 */
	private static Logger logger = Logger.getLogger(SimonServer.class);

	private SimonServer() {

	}

	public static void initServer(BlockingQueue<EinsatzAlarm> list) {

		try {

			// System.setProperty("java.rmi.server.hostname",
			// config.getRmiServerHostname());
			// logger.info("Hostname: " + config.getRmiServerHostname());
			// logger.info("Registerport: " + config.getRmiRegistryPort());
			// LocateRegistry.createRegistry(config.getRmiRegistryPort());
			// String chat_registry_name = "rmi://" + config.getRmiRegistryIp()
			// + ":"
			// + config.getRmiRegistryPort() + "/Server";
			// logger.debug(chat_registry_name);
			// logger.info("Server an den Namen: " + chat_registry_name +
			// " binden");
			// Naming.rebind(chat_registry_name, new RMIServer());

			// create the serverobject
			AlarmServerInterfaceImpl serverImpl = new AlarmServerInterfaceImpl(
					list);

			// create the server's registry ...
			Registry registry;

			registry = Simon.createRegistry(22222);

			// ... where we can bind the serverobject to
			registry.bind("server", serverImpl);

			logger.info("Server online!");
		} catch (IOException | NameBindingException e) {

			logger.error("", e);
		}
	}
}
